package es.mgil.soaTest;

import es.mgil.soaTest.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class RestTweetsActivity extends Activity {
	private ListView tweet_list;
	private AdapterElements adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rest_tweets_layout);
		tweet_list = (ListView) findViewById(R.id.listView1);
		adapter = new AdapterElements(this);
		tweet_list.setAdapter(adapter);
	}

	class AdapterElements extends ArrayAdapter<Object> {
		private Activity context;

		public AdapterElements(Activity context) {
			super(context, R.layout.rest_tweet_layout, RestMainActivity.tweets);
			this.context = context;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			LayoutInflater inflater = context.getLayoutInflater();
			View item = inflater.inflate(R.layout.rest_tweet_layout, null);

			// Carga Nombre
			TextView lblUser = (TextView) item.findViewById(R.id.textView1);
			lblUser.setText((position + 1) + ". "
					+ RestMainActivity.tweets[position].getUser());

			// Carga Tweet
			TextView lblTweet = (TextView) item.findViewById(R.id.textView2);
			lblTweet.setText(RestMainActivity.tweets[position].getTweet());

			return (item);
		}
	}
}
